#include <iostream>
using namespace std;

int n, arr[10], sf[10];

void dfs(int cur)
{
    if(cur == n)
    {
        for(int i = 0; i < n; ++i) cout << arr[i] << ' ';
        cout << endl;
        return;
    }
    for(int i = 1; i <= n; ++i)
    {
        if(sf[i]) continue;
        sf[i] = 1;
        arr[cur] = i;
        dfs(cur + 1);
        sf[i] = 0;
    }
}

int main()
{
    cin >> n;
    dfs(0);
    return 0;
}